package com.qsw.paper.controller.admin;


import cn.hutool.core.bean.BeanUtil;
import com.qsw.paper.constant.JwtClaimsConstant;
import com.qsw.paper.constant.MessageConstants;
import com.qsw.paper.pojo.entity.Users;
import com.qsw.paper.result.Result;
import com.qsw.paper.service.IUsersService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author qsw
 * @since 2024-11-16
 */
@RestController("adminUsersController")
@RequestMapping("/admin/users")
@RequiredArgsConstructor
@Slf4j
public class UsersController {

    private final IUsersService usersService;


    /**
     * 重置用户密码
     *
     * @param id 用户id
     * @return 提示
     */
    @PutMapping("/resetPa/{id}")
    public Result<?> resetUserPasswordById(@PathVariable Integer id) {
        log.info("管理员重置用户密码:{}", id);
        usersService.updateById(Users.builder().userId(id)
                .password(DigestUtils.md5DigestAsHex(JwtClaimsConstant.INITIAL_PASSWORD.getBytes())).build());
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }
}
